package de.baumann.browser.activitys

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.utils.getBoolean

class SplashActivity : BaseOdinActivity<IBaseView, BasePresenter<IBaseView>>() {

    private var startTime: Long = 0
    private var D = 3000

    override fun onCreate(savedInstanceState: Bundle?) {
        startTime = System.currentTimeMillis()
        super.onCreate(savedInstanceState)
    }

    override fun getLayout(): Int {
        return R.layout.activity_splash
    }

    override fun initView() {
        val endTime = System.currentTimeMillis()
        val d = endTime - startTime
        if (d > D) {
            handler.sendEmptyMessage(0)
        } else {
            handler.sendEmptyMessageDelayed(0, D - d)
        }
    }

    private var handler: Handler = Handler(Handler.Callback {
        val intent = intent
        when {
           /* intent.hasExtra(NimIntent.EXTRA_NOTIFY_CONTENT) -> {
                // 打开客服窗口
                UnicornUtil.openServiceActivity(mContext, javaClass.name, 1)
                // 最好将intent清掉，以免从堆栈恢复时又打开客服窗口
                setIntent(Intent())
                finish()
            }*/
            getBoolean("guide") -> {
                startActivity(Intent(mContext, MainActivity::class.java))
                finish()
            }
            else -> {
                startActivity(Intent(mContext, GuideActivity::class.java))
                finish()
            }
        }
        false
    })

    override fun initData() {
    }

    override fun createPresenter(): BasePresenter<IBaseView>? {
        return null
    }

    override fun createView(): IBaseView? {
        return null
    }

    override fun showBindEth(): Boolean {
        return false
    }
}
